package tp3.commands.extension;

import java.io.File;

import tp3.commands.AbstractCommand;
import tp3.commands.ICommand;

public class Size extends AbstractCommand implements ICommand {

	public Size() {
		super("Size");
	}

	@Override
	protected void manageNone() {
		append("Aucune Selection");
	}

	@Override
	protected void manageFile(File f) {
		append(String.valueOf(f.length()));

	}

	@Override
	protected void manageDirectory(File f) {
		append(String.valueOf(manageDir(f)));

	}
	
	private long manageDir(File f) {
		long size = 0;
		File[] listFiles = f.listFiles();
		for (File file : listFiles) {
			if (file.isDirectory()) {
				size += manageDir(file);
			} else
				size += file.length();
		}
		return size;
	}

}
